package com.brisk.web.controller.applet;

import com.ruoyi.applet.domain.AppletImg;
import com.ruoyi.applet.service.IAppletImgService;
import com.brisk.common.annotation.Log;
import com.brisk.common.core.controller.BaseController;
import com.brisk.common.core.domain.AjaxResult;
import com.brisk.common.core.page.TableDataInfo;
import com.brisk.common.enums.BusinessType;
import com.brisk.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * appletImgController
 *
 * @author PENGFEIDENG
 * @date 2022-05-30
 */
@RestController
@RequestMapping("/applet/appletImg")
public class AppletImgController extends BaseController {
    @Autowired
    private IAppletImgService appletImgService;

    /**
     * 查询appletImg列表
     */
    @PreAuthorize("@ss.hasPermi('applet:appletImg:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppletImg appletImg) {
        startPage();
        List<AppletImg> list = appletImgService.selectAppletImgList(appletImg);
        return getDataTable(list);
    }

    /**
     * 导出appletImg列表
     */
    @PreAuthorize("@ss.hasPermi('applet:appletImg:export')")
    @Log(title = "appletImg", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AppletImg appletImg) {
        List<AppletImg> list = appletImgService.selectAppletImgList(appletImg);
        ExcelUtil<AppletImg> util = new ExcelUtil<AppletImg>(AppletImg.class);
        util.exportExcel(response, list, "素材图片");
    }

    /**
     * 获取appletImg详细信息
     */
    @PreAuthorize("@ss.hasPermi('applet:appletImg:query')")
    @GetMapping(value = "/{imgId}")
    public AjaxResult getInfo(@PathVariable("imgId") Long imgId) {
        return AjaxResult.success(appletImgService.selectAppletImgByImgId(imgId));
    }

    /**
     * 新增appletImg
     */
    @PreAuthorize("@ss.hasPermi('applet:appletImg:add')")
    @Log(title = "appletImg", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppletImg appletImg) {
        return toAjax(appletImgService.insertAppletImg(appletImg));
    }

    /**
     * 修改appletImg
     */
    @PreAuthorize("@ss.hasPermi('applet:appletImg:edit')")
    @Log(title = "appletImg", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppletImg appletImg) {
        return toAjax(appletImgService.updateAppletImg(appletImg));
    }

    /**
     * 删除appletImg
     */
    @PreAuthorize("@ss.hasPermi('applet:appletImg:remove')")
    @Log(title = "appletImg", businessType = BusinessType.DELETE)
    @DeleteMapping("/{imgIds}")
    public AjaxResult remove(@PathVariable Long[] imgIds) {
        return toAjax(appletImgService.deleteAppletImgByImgIds(imgIds));
    }
}
